package com.ccExcelUtil.convertObject;

import com.ccExcelUtil.validator.ValidatorUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiaozhao
 */
public class ConvertData {

    public static <T, E> List<E> convert(List<T> list) {
        List<E> result = new ArrayList<>();
        if (list.isEmpty()) {
            throw new RuntimeException("list is empty");
        }
        T entity = list.get(0);
        ConvertObjectService<Object, Object> objectObjectConvertObjectService = ValidatorUtils.CONVERT_OBJECT_SERVICE_MAP.get(entity.getClass().getName());
        for (T t : list) {
            E e = (E) objectObjectConvertObjectService.convert(t);
            result.add(e);
        }
        return result;
    }
}
